#include "main.h"

//(W_HEIGHT-B_SIZE)-(loop*B_SIZE)
void Info::drawinfo()
{
	glMatrixMode(GL_MODELVIEW); 
	glLoadIdentity();
	gluLookAt(0,0,720.0f,0,0,0,0,1,0);

	int offset = W_HEIGHT-480;
	glBindTexture(GL_TEXTURE_2D,pictures[0]); //pachead title

		glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)px*scale-(W_WIDTH/2), (GLfloat)py*scale-(W_HEIGHT/2),  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(px+110)*scale-(W_WIDTH/2), (GLfloat)py*scale-(W_HEIGHT/2),  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(px+110)*scale-(W_WIDTH/2),  (GLfloat)(py+64)*scale-(W_HEIGHT/2),  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)px*scale-(W_WIDTH/2),  (GLfloat)(py+64)*scale-(W_HEIGHT/2),  0.0f);	// Top Left Of The Texture and Quad
		glEnd();


	switch(pachead.state)
	{
	case NORM: 
		{
			if(difficulty > 1)
				glColor3f(WHITE);
			else
				glColor3f(PACGREEN);
		}break;
	case POWER: glColor3f(PACRED);break;
	case SPEED: glColor3f(PACYELLOW);break;
	case INVIS: glColor3f(PACGRAY);break;
	case GHOST: glColor3f(WHITE);break;
	};

	if(difficulty > 1)
	{
		glBindTexture(GL_TEXTURE_2D,pachead.sprites[5][((int)(pachead.x+pachead.y+W_WIDTH)/18)%2]);
	}
	else
	{
		glBindTexture(GL_TEXTURE_2D,pachead.sprites[5][((int)(pachead.x+pachead.y+W_WIDTH)/18)%2]);
	}

	double offset2 = B_SIZE;
		glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)hx*scale-(W_WIDTH/2)-offset2, (GLfloat)hy*scale-(W_HEIGHT/2)-offset2,  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(hx+48)*scale-(W_WIDTH/2)+offset2, (GLfloat)hy*scale-(W_HEIGHT/2)-offset2,  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(hx+48)*scale-(W_WIDTH/2)+offset2,  (GLfloat)(hy+48)*scale-(W_HEIGHT/2)+offset2,  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)hx*scale-(W_WIDTH/2)-offset2,  (GLfloat)(hy+48)*scale-(W_HEIGHT/2)+offset2,  0.0f);	// Top Left Of The Texture and Quad
		glEnd();

	glColor3f(WHITE);


	cnum.drawnumber(pachead.lives,(int)(plx*scale)-(W_WIDTH/2),(int)(ply*scale)-(W_HEIGHT/2));
	cnum.drawnumber(pachead.health, (int)(532*scale)-(W_WIDTH/2),(int)(310*scale)-(W_HEIGHT/2));


	glBindTexture(GL_TEXTURE_2D,pictures[1]); //level

		glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)lx*scale-(W_WIDTH/2), (GLfloat)ly*scale-(W_HEIGHT/2),  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(lx+64)*scale-(W_WIDTH/2), (GLfloat)ly*scale-(W_HEIGHT/2),  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(lx+64)*scale-(W_WIDTH/2),  (GLfloat)(ly+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)lx*scale-(W_WIDTH/2),  (GLfloat)(ly+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Left Of The Texture and Quad
		glEnd();



	cnum.drawnumber(pachead.level,(int)(lvx*scale)-(W_WIDTH/2),(int)(lvy*scale)-(W_HEIGHT/2));





	glBindTexture(GL_TEXTURE_2D,pictures[2]); //music

		glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)mx*scale-(W_WIDTH/2), (GLfloat)my*scale-(W_HEIGHT/2),  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(mx+64)*scale-(W_WIDTH/2), (GLfloat)my*scale-(W_HEIGHT/2),  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(mx+64)*scale-(W_WIDTH/2),  (GLfloat)(my+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)mx*scale-(W_WIDTH/2),  (GLfloat)(my+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Left Of The Texture and Quad
		glEnd();

		cnum.drawnumber(songnum+1, (int)(530*scale)-(W_WIDTH/2), (int)(190*scale)-(W_HEIGHT/2));

	glBindTexture(GL_TEXTURE_2D,pictures[3]); //score

		glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)sx*scale-(W_WIDTH/2), (GLfloat)sy*scale-(W_HEIGHT/2),  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(sx+64)*scale-(W_WIDTH/2), (GLfloat)sy*scale-(W_HEIGHT/2),  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(sx+64)*scale-(W_WIDTH/2),  (GLfloat)(sy+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)sx*scale-(W_WIDTH/2),  (GLfloat)(sy+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Left Of The Texture and Quad
		glEnd();


		cnum.drawnumber(pachead.score, (int)(530*scale)-(W_WIDTH/2), (int)(115*scale)-(W_HEIGHT/2));
		cnum.drawnumber(highscore, (int)(530*scale)-(W_WIDTH/2), (int)(80*scale)-(W_HEIGHT/2));

}

void Info::loadpictures()
{
	char *picfiles[] =
	{ 
		"sprite/pactitle.bmp",
		"sprite/level.bmp",
		"sprite/music.bmp",
		"sprite/score.bmp",
		"sprite/gameover.bmp"
	};	

	for(int index = 0; index < 5; index++)
	{
		pictures[index] = LoadGLTextures(picfiles[index]);

	}

	px = 530; py = 416;//416

	lx = 532; ly = 280;//300
	mx = 532; my = 220;//220
	sx = 532; sy = 150;//150

	hx = 560;  hy = 364; //560, 364
	lvx = 530; lvy = 250;//566 , 270

	plx = 564; ply = 338; //564, 338

}

void Info::mapintro()
{

	DWORD wait = timeGetTime();

	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective (45.0f, 1.0, 1, 1000);
	glOrtho(-1*(W_WIDTH/2),(W_WIDTH/2),-1*(W_HEIGHT/2),(W_HEIGHT/2),0.0,-1000.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0,0,720.0f,0,0,0,0,1,0);

	glBindTexture(GL_TEXTURE_2D,pictures[1]); //level

	glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)230*scale-(W_WIDTH/2), (GLfloat)228*scale-(W_HEIGHT/2),  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(230+64)*scale-(W_WIDTH/2), (GLfloat)(228*scale)-(W_HEIGHT/2),  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(230+64)*scale-(W_WIDTH/2),  (GLfloat)(228+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)(230*scale)-(W_WIDTH/2),  (GLfloat)(228+24)*scale-(W_HEIGHT/2),  0.0f);	// Top Left Of The Texture and Quad
	glEnd();

	cnum.drawnumber(pachead.level,310*scale-(W_WIDTH/2),228*scale-(W_HEIGHT/2));

	SwapBuffers(hDC);

	do
	{
	}while((timeGetTime() - wait) < 3000);

}

void Info::gameover()
{
	DWORD wait = timeGetTime();

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective (45.0f, 1.0, 1, 1000);
	glOrtho(-1*(W_WIDTH/2),(W_WIDTH/2),-1*(W_HEIGHT/2),(W_HEIGHT/2),0.0,-1000.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(0,0,720.0f,0,0,0,0,1,0);

	


	glBindTexture(GL_TEXTURE_2D,pictures[4]); //game over

	glBegin(GL_QUADS); //draw the tiles
			glTexCoord2f(0.0f, 0.0f); glVertex3f((GLfloat)104*scale-(W_WIDTH/2), (GLfloat)228*scale-(W_HEIGHT/2),  0.0f);	// Bottom Left Of The Texture and Quad
			glTexCoord2f(1.0f, 0.0f); glVertex3f( (GLfloat)(104+384)*scale-(W_WIDTH/2), (GLfloat)228*scale-(W_HEIGHT/2),  0.0f);	// Bottom Right Of The Texture and Quad
			glTexCoord2f(1.0f, 1.0f); glVertex3f( (GLfloat)(104+384)*scale-(W_WIDTH/2),  (GLfloat)(228+64)*scale-(W_HEIGHT/2),  0.0f);	// Top Right Of The Texture and Quad
			glTexCoord2f(0.0f, 1.0f); glVertex3f((GLfloat)104*scale-(W_WIDTH/2),  (GLfloat)(228+64)*scale-(W_HEIGHT/2),  0.0f);	// Top Left Of The Texture and Quad
	glEnd();


	SwapBuffers(hDC);

	do
	{

	}while((timeGetTime() - wait) < 4500);

}